/**
 * State.java
 * 
 * Created by Chad Cross on 4/5/09
 * 
 * @author Chad Cross
 * @version 1.1
 * 
 * This class is a data structure needed to define a state in a
 * finite automaton.
 * 
 * Adapted from Amer Gerzic's regex library: http://www.amergerzic.com/page/Free-Downloads.aspx
 * Licensed under the Code Project Open License: http://www.codeproject.com/info/cpol10.aspx
 * 
 */

package jmai.parser;

import java.util.*;

public class State implements Comparable{

	/** The name of the state */
	public String stateName;
	
	/** List of transitions between states */
	public ArrayList transitionsArray = new ArrayList();
	
	/** A list of states in the NFA for use in the DFA construction */
	public ArrayList NFAStates = new ArrayList();
	
	/**
	 * The default constructor
	 */
	public State(String aName) {
		stateName = aName;	
	}//end default constructor
	
	public State (ArrayList stateArray) {
		NFAStates.addAll(stateArray);
		
		if(NFAStates.size() > 0) {
			stateName = "{" + ((State)(NFAStates.get(0))).stateName;
			
			for (int i = 1; i< NFAStates.size(); ++i) 
				stateName += "," + ((State)(NFAStates.get(i))).stateName;
			
			stateName += "}";				
		}//end if
		
		
	}//end secondary constructor
	
	/**
	 * Overriding the compare function will allow use for collections
	 * that use comparisons
	 */
	public int compareTo(Object o) {
		return(stateName.compareTo(((State)o).stateName));
	}//end method compareTo
}//end class State
